
package uaem.tituaem.ftp;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;


public class ConexionFTP {
    
    private String user;
    private String pass;
    private String host;
    private int port;
    private FTPClient ftp=new FTPClient();    
    
    //contructores
    
    public ConexionFTP(String user, String pass, String host, int port) {
        this.user = user;
        this.pass = pass;
        this.host = host;
        this.port = port;
        
    }

    public ConexionFTP() {
        
        this.host="tituaem.esy.es";
        this.user="u847224180";
        this.pass="1234567";
        this.port=21;
        
        
    }
    
    //Metodos
    
        //
    protected FTPClient conectarFTP() throws IOException{
        
        boolean valor;
        int resp=0;
        
        ftp.connect(host, port);
        ftp.login(user, pass);
        ftp.enterLocalPassiveMode();
        resp=ftp.getReplyCode();
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        
            if(FTPReply.isPositiveCompletion(resp)==true){
                System.out.println("Se conecto con ftp");    
            }
            else{
                System.out.println("No se conecto con ftp"); 
            }
        return ftp;
        
    }
    
    protected void desconectar() throws IOException{
        ftp.logout();
        ftp.disconnect();
    }
        
        //getters
                    public String getUser() {
                        return user;
                    }

                    public String getPass() {
                        return pass;
                    }

                    public String getHost() {
                        return host;
                    }
    
    
    
    
    
    
    
    
    
    
    
    //main para pruebas
    
    public static void main(String[] args) {
        
        ConexionFTP sa=new ConexionFTP();
        
        
        try {
            
            System.out.println(sa.conectarFTP());
            
        } catch (IOException ex) {
            Logger.getLogger(ConexionFTP.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }
    
    
    
}
